github.com/jmrodri/operator-sdk@v0.5.0/pkg/scaffold/test_setup.go (about)

     1  // Copyright 2018 The Operator-SDK Authors
     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 scaffold
    16  
    17  import (
    18  	"bytes"
    19  	"io"
    20  	"os"
    21  	"path/filepath"
    22  
    23  	"github.com/operator-framework/operator-sdk/pkg/scaffold/input"
    24  
    25  	log "github.com/sirupsen/logrus"
    26  )
    27  
    28  const (
    29  	// test constants describing an app operator project
    30  	appProjectName = "app-operator"
    31  	appRepo        = "github.com" + filePathSep + "example-inc" + filePathSep + appProjectName
    32  	appApiVersion  = "app.example.com/v1alpha1"
    33  	appKind        = "AppService"
    34  )
    35  
    36  var (
    37  	appConfig = &input.Config{
    38  		Repo:           appRepo,
    39  		AbsProjectPath: mustGetImportPath(),
    40  		ProjectName:    appProjectName,
    41  	}
    42  )
    43  
    44  func mustGetImportPath() string {
    45  	wd, err := os.Getwd()
    46  	if err != nil {
    47  		log.Fatalf("Failed to get working directory: (%v)", err)
    48  	}
    49  	return filepath.Join(wd, appRepo)
    50  }
    51  
    52  func setupScaffoldAndWriter() (*Scaffold, *bytes.Buffer) {
    53  	buf := &bytes.Buffer{}
    54  	return &Scaffold{
    55  		GetWriter: func(_ string, _ os.FileMode) (io.Writer, error) {
    56  			return buf, nil
    57  		},
    58  	}, buf
    59  }