github.com/coreos/mantle@v0.13.0/update/generator/info_test.go (about) 1 // Copyright 2016 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package generator 16 17 import ( 18 "bytes" 19 "testing" 20 ) 21 22 func TestEmptyInstallInfo(t *testing.T) { 23 info, err := NewInstallInfo(bytes.NewReader([]byte{})) 24 if err != nil { 25 t.Fatal(err) 26 } 27 28 if info.Size == nil { 29 t.Error("InstallInfo.Size is nil") 30 } else if *info.Size != 0 { 31 t.Errorf("InstallInfo.Size should be 0, got %d", *info.Size) 32 } 33 34 if !bytes.Equal(info.Hash, testEmptyHash) { 35 t.Errorf("InstallInfo.Hash should be %q, got %q", testEmptyHash, info.Hash) 36 } 37 } 38 39 func TestOnesInstallInfo(t *testing.T) { 40 info, err := NewInstallInfo(bytes.NewReader(testOnes)) 41 if err != nil { 42 t.Fatal(err) 43 } 44 45 if info.Size == nil { 46 t.Error("InstallInfo.Size is nil") 47 } else if *info.Size != BlockSize { 48 t.Errorf("InstallInfo.Size should be %d, got %d", BlockSize, *info.Size) 49 } 50 51 if !bytes.Equal(info.Hash, testOnesHash) { 52 t.Errorf("InstallInfo.Hash should be %q, got %q", testOnesHash, info.Hash) 53 } 54 } 55 56 func TestUnalignedInstallInfo(t *testing.T) { 57 info, err := NewInstallInfo(bytes.NewReader(testUnaligned)) 58 if err != nil { 59 t.Fatal(err) 60 } 61 62 if info.Size == nil { 63 t.Error("InstallInfo.Size is nil") 64 } else if *info.Size != BlockSize+1 { 65 t.Errorf("InstallInfo.Size should be %d, got %d", BlockSize, *info.Size) 66 } 67 68 if !bytes.Equal(info.Hash, testUnalignedHash) { 69 t.Errorf("InstallInfo.Hash should be %q, got %q", testUnalignedHash, info.Hash) 70 } 71 }