Skip to content

Commit

Permalink
Forgot to add test file
Browse files Browse the repository at this point in the history
  • Loading branch information
sixolet committed Aug 9, 2019
1 parent 5575182 commit aa4718b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/serving/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright © 2018 The Knative 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 serving

import (
"math/rand"
"testing"

"gotest.tools/assert"

servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1"
)

type generateNameTest struct {
templ string
result string
err string
}

func TestGenerateName(t *testing.T) {
rand.Seed(1)
someRandomChars := (&revisionTemplContext{}).Random(20)
service := &servingv1alpha1.Service{}
service.Name = "foo"
service.Generation = 3
cases := []generateNameTest{
{"{{.Service}}-v-{{.Generation}}", "foo-v-4", ""},
{"foo-asdf", "foo-asdf", ""},
{"{{.Bad}}", "", "can't evaluate field Bad"},
{"{{.Service}}-{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
}
for _, c := range cases {
rand.Seed(1)
name, err := GenerateRevisionName(c.templ, service)
if c.err != "" {
assert.ErrorContains(t, err, c.err)
} else {
assert.Equal(t, name, c.result)
}
}
}

0 comments on commit aa4718b

Please sign in to comment.