/* Copyright 2015 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package rkt import ( "fmt" "testing" rktapi "github.com/coreos/rkt/api/v1alpha" "github.com/stretchr/testify/assert" ) func TestCheckVersion(t *testing.T) { fr := newFakeRktInterface() fs := newFakeSystemd() r := &Runtime{apisvc: fr, systemd: fs} fr.info = rktapi.Info{ RktVersion: "1.2.3+git", AppcVersion: "1.2.4+git", ApiVersion: "1.2.6-alpha", } fs.version = "100" tests := []struct { minimumRktBinVersion string recommendedRktBinVersion string minimumAppcVersion string minimumRktApiVersion string minimumSystemdVersion string err error calledGetInfo bool calledSystemVersion bool }{ // Good versions. { "1.2.3", "1.2.3", "1.2.4", "1.2.5", "99", nil, true, true, }, // Good versions. { "1.2.3+git", "1.2.3+git", "1.2.4+git", "1.2.6-alpha", "100", nil, true, true, }, // Requires greater binary version. { "1.2.4", "1.2.4", "1.2.4", "1.2.6-alpha", "100", fmt.Errorf("rkt: binary version is too old(%v), requires at least %v", fr.info.RktVersion, "1.2.4"), true, true, }, // Requires greater Appc version. { "1.2.3", "1.2.3", "1.2.5", "1.2.6-alpha", "100", fmt.Errorf("rkt: appc version is too old(%v), requires at least %v", fr.info.AppcVersion, "1.2.5"), true, true, }, // Requires greater API version. { "1.2.3", "1.2.3", "1.2.4", "1.2.6", "100", fmt.Errorf("rkt: API version is too old(%v), requires at least %v", fr.info.ApiVersion, "1.2.6"), true, true, }, // Requires greater API version. { "1.2.3", "1.2.3", "1.2.4", "1.2.7", "100", fmt.Errorf("rkt: API version is too old(%v), requires at least %v", fr.info.ApiVersion, "1.2.7"), true, true, }, // Requires greater systemd version. { "1.2.3", "1.2.3", "1.2.4", "1.2.7", "101", fmt.Errorf("rkt: systemd version(%v) is too old, requires at least %v", fs.version, "101"), false, true, }, } for i, tt := range tests { testCaseHint := fmt.Sprintf("test case #%d", i) err := r.checkVersion(tt.minimumRktBinVersion, tt.recommendedRktBinVersion, tt.minimumAppcVersion, tt.minimumRktApiVersion, tt.minimumSystemdVersion) assert.Equal(t, err, tt.err, testCaseHint) if tt.calledGetInfo { assert.Equal(t, fr.called, []string{"GetInfo"}, testCaseHint) } if tt.calledSystemVersion { assert.Equal(t, fs.called, []string{"Version"}, testCaseHint) } if err == nil { assert.Equal(t, r.binVersion.String(), fr.info.RktVersion, testCaseHint) assert.Equal(t, r.appcVersion.String(), fr.info.AppcVersion, testCaseHint) assert.Equal(t, r.apiVersion.String(), fr.info.ApiVersion, testCaseHint) } fr.CleanCalls() fs.CleanCalls() } }