Skip to content

Commit

Permalink
Add unit test for remote asset processor
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Oct 12, 2022
1 parent 7b45bb7 commit 5fa8504
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/publish-release/cmd/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2022 The Kubernetes Authors.
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 cmd

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestProcessRemoteAsset(t *testing.T) {
// Remove the fefault app creds temporarily
const gacVar = "GOOGLE_APPLICATION_CREDENTIALS"
prev := os.Getenv(gacVar)
defer t.Setenv(gacVar, prev)
t.Setenv(gacVar, "")

files := []string{}
defer func() {
for _, f := range files {
os.RemoveAll(f)
}
}()
path, err := processRemoteAsset("gs://kubernetes-release/release/v1.25.1/kubernetes.tar.gz.sha512")
require.NoError(t, err)
require.FileExists(t, path)
require.Equal(t, "kubernetes.tar.gz.sha512", filepath.Base(path))
files = append(files, path)

// Non existent object should fail
_, err = processRemoteAsset("gs://kubernetes-release/release/v1.25.1/0000000")
require.Error(t, err)
}

0 comments on commit 5fa8504

Please sign in to comment.