Skip to content

Commit 571ae4b

Browse files
authored
Merge pull request #202 from operator-framework/refactor_generator
pkg/generator: use app test constants for all test cases
2 parents b0d1c30 + d8a208f commit 571ae4b

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

pkg/generator/generator_test.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
const (
2323
// test constants for app-operator
24-
appRepoPath = "github.com/example-inc/app-operator"
24+
appRepoPath = "github.com/example-inc/" + appProjectName
2525
appKind = "AppService"
2626
appApiDirName = "app"
2727
appAPIVersion = appGroupName + "/" + appVersion
@@ -94,7 +94,7 @@ type Handler struct {
9494
9595
func (h *Handler) Handle(ctx types.Context, event types.Event) error {
9696
switch o := event.Object.(type) {
97-
case *v1alpha1.App:
97+
case *v1alpha1.AppService:
9898
err := action.Create(newbusyBoxPod(o))
9999
if err != nil && !errors.IsAlreadyExists(err) {
100100
logrus.Errorf("Failed to create busybox pod : %v", err)
@@ -105,7 +105,7 @@ func (h *Handler) Handle(ctx types.Context, event types.Event) error {
105105
}
106106
107107
// newbusyBoxPod demonstrates how to create a busybox pod
108-
func newbusyBoxPod(cr *v1alpha1.App) *v1.Pod {
108+
func newbusyBoxPod(cr *v1alpha1.AppService) *v1.Pod {
109109
labels := map[string]string{
110110
"app": "busy-box",
111111
}
@@ -162,7 +162,7 @@ import (
162162
163163
const (
164164
version = "v1alpha1"
165-
groupName = "play.example.com"
165+
groupName = "app.example.com"
166166
)
167167
168168
var (
@@ -179,8 +179,8 @@ func init() {
179179
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
180180
func addKnownTypes(scheme *runtime.Scheme) error {
181181
scheme.AddKnownTypes(SchemeGroupVersion,
182-
&PlayService{},
183-
&PlayServiceList{},
182+
&AppService{},
183+
&AppServiceList{},
184184
)
185185
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
186186
return nil
@@ -189,7 +189,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
189189

190190
func TestGenRegister(t *testing.T) {
191191
buf := &bytes.Buffer{}
192-
if err := renderAPIRegisterFile(buf, "PlayService", "play.example.com", "v1alpha1"); err != nil {
192+
if err := renderAPIRegisterFile(buf, appKind, appGroupName, appVersion); err != nil {
193193
t.Error(err)
194194
return
195195
}
@@ -254,25 +254,24 @@ fi
254254
255255
BIN_DIR="$(pwd)/tmp/_output/bin"
256256
mkdir -p ${BIN_DIR}
257-
PROJECT_NAME="play"
258-
REPO_PATH="github.com/coreos/play"
257+
PROJECT_NAME="app-operator"
258+
REPO_PATH="github.com/example-inc/app-operator"
259259
BUILD_PATH="${REPO_PATH}/cmd/${PROJECT_NAME}"
260260
echo "building "${PROJECT_NAME}"..."
261261
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ${BIN_DIR}/${PROJECT_NAME} $BUILD_PATH
262262
`
263263

264264
const dockerFileExp = `FROM alpine:3.6
265265
266-
ADD tmp/_output/bin/play /usr/local/bin/play
266+
ADD tmp/_output/bin/app-operator /usr/local/bin/app-operator
267267
268-
RUN adduser -D play
269-
USER play
268+
RUN adduser -D app-operator
269+
USER app-operator
270270
`
271271

272272
func TestGenBuild(t *testing.T) {
273273
buf := &bytes.Buffer{}
274-
projectName := "play"
275-
if err := renderBuildFile(buf, "github.com/coreos/play", projectName); err != nil {
274+
if err := renderBuildFile(buf, appRepoPath, appProjectName); err != nil {
276275
t.Error(err)
277276
return
278277
}
@@ -290,7 +289,7 @@ func TestGenBuild(t *testing.T) {
290289
}
291290

292291
buf = &bytes.Buffer{}
293-
if err := renderDockerFile(buf, projectName); err != nil {
292+
if err := renderDockerFile(buf, appProjectName); err != nil {
294293
t.Error(err)
295294
return
296295
}
@@ -308,7 +307,7 @@ set -o errexit
308307
set -o nounset
309308
set -o pipefail
310309
311-
DOCKER_REPO_ROOT="/go/src/github.com/coreos/play"
310+
DOCKER_REPO_ROOT="/go/src/github.com/example-inc/app-operator"
312311
IMAGE=${IMAGE:-"gcr.io/coreos-k8s-scale-testing/codegen:1.9.3"}
313312
314313
docker run --rm \
@@ -317,16 +316,16 @@ docker run --rm \
317316
"$IMAGE" \
318317
"/go/src/k8s.io/code-generator/generate-groups.sh" \
319318
"deepcopy" \
320-
"github.com/coreos/play/pkg/generated" \
321-
"github.com/coreos/play/pkg/apis" \
322-
"play:v1alpha1" \
319+
"github.com/example-inc/app-operator/pkg/generated" \
320+
"github.com/example-inc/app-operator/pkg/apis" \
321+
"app:v1alpha1" \
323322
--go-header-file "./tmp/codegen/boilerplate.go.txt" \
324323
$@
325324
`
326325

327326
func TestCodeGen(t *testing.T) {
328327
buf := &bytes.Buffer{}
329-
if err := renderBoilerplateFile(buf, "play"); err != nil {
328+
if err := renderBoilerplateFile(buf, appProjectName); err != nil {
330329
t.Error(err)
331330
return
332331
}
@@ -335,7 +334,7 @@ func TestCodeGen(t *testing.T) {
335334
}
336335

337336
buf = &bytes.Buffer{}
338-
if err := renderUpdateGeneratedFile(buf, "github.com/coreos/play", "play", "v1alpha1"); err != nil {
337+
if err := renderUpdateGeneratedFile(buf, appRepoPath, appApiDirName, appVersion); err != nil {
339338
t.Error(err)
340339
return
341340
}
@@ -372,7 +371,7 @@ projectName: app-operator
372371

373372
func TestGenConfig(t *testing.T) {
374373
buf := &bytes.Buffer{}
375-
if err := renderConfigFile(buf, "app.example.com/v1alpha1", "AppService", "app-operator"); err != nil {
374+
if err := renderConfigFile(buf, appAPIVersion, appKind, appProjectName); err != nil {
376375
t.Error(err)
377376
}
378377
if configExp != buf.String() {

0 commit comments

Comments
 (0)