Use a standard Go project layout
[multicloud/k8s.git] / src / k8splugin / internal / rb / archive_test.go
1 /*
2  * Copyright 2018 Intel Corporation, Inc
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package rb
18
19 import (
20         "bytes"
21         "testing"
22 )
23
24 func TestIsTarGz(t *testing.T) {
25
26         t.Run("Valid tar.gz", func(t *testing.T) {
27                 content := []byte{
28                         0x1f, 0x8b, 0x08, 0x08, 0xb0, 0x6b, 0xf4, 0x5b,
29                         0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
30                         0x61, 0x72, 0x00, 0xed, 0xce, 0x41, 0x0a, 0xc2,
31                         0x30, 0x10, 0x85, 0xe1, 0xac, 0x3d, 0x45, 0x4e,
32                         0x50, 0x12, 0xd2, 0xc4, 0xe3, 0x48, 0xa0, 0x01,
33                         0x4b, 0x52, 0x0b, 0xed, 0x88, 0x1e, 0xdf, 0x48,
34                         0x11, 0x5c, 0x08, 0xa5, 0x8b, 0x52, 0x84, 0xff,
35                         0xdb, 0xbc, 0x61, 0x66, 0x16, 0x4f, 0xd2, 0x2c,
36                         0x8d, 0x3c, 0x45, 0xed, 0xc8, 0x54, 0x21, 0xb4,
37                         0xef, 0xb4, 0x67, 0x6f, 0xbe, 0x73, 0x61, 0x9d,
38                         0xb2, 0xce, 0xd5, 0x55, 0xf0, 0xde, 0xd7, 0x3f,
39                         0xdb, 0xd6, 0x49, 0x69, 0xb3, 0x67, 0xa9, 0x8f,
40                         0xfb, 0x2c, 0x71, 0xd2, 0x5a, 0xc5, 0xee, 0x92,
41                         0x73, 0x8e, 0x43, 0x7f, 0x4b, 0x3f, 0xff, 0xd6,
42                         0xee, 0x7f, 0xea, 0x9a, 0x4a, 0x19, 0x1f, 0xe3,
43                         0x54, 0xba, 0xd3, 0xd1, 0x55, 0x00, 0x00, 0x00,
44                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45                         0x00, 0x00, 0x00, 0x1b, 0xbc, 0x00, 0xb5, 0xe8,
46                         0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
47                 }
48
49                 err := isTarGz(bytes.NewBuffer(content))
50                 if err != nil {
51                         t.Errorf("Error reading valid Zip file %s", err.Error())
52                 }
53         })
54
55         t.Run("Invalid tar.gz", func(t *testing.T) {
56                 content := []byte{
57                         0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
58                         0x00, 0xff, 0xf2, 0x48, 0xcd,
59                 }
60
61                 err := isTarGz(bytes.NewBuffer(content))
62                 if err == nil {
63                         t.Errorf("Error should NOT be nil")
64                 }
65         })
66 }