github.com/sap/cf-mta-plugin@v2.6.3+incompatible/testutil/test_results.go (about)

     1  package testutil
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  
     7  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/models"
     8  	"github.com/go-openapi/runtime"
     9  )
    10  
    11  var SimpleOperationResult = models.Operation{
    12  	State:    "FINISHED",
    13  	Messages: []*models.Message{&SimpleMessage},
    14  }
    15  
    16  var SimpleMessage = models.Message{
    17  	ID:   0,
    18  	Type: "INFO",
    19  	Text: "Test message",
    20  }
    21  
    22  var GetMessage = func(id int64, message string) *models.Message {
    23  	return &models.Message{
    24  		ID:   id,
    25  		Type: "INFO",
    26  		Text: message,
    27  	}
    28  }
    29  
    30  var OperationResult = models.Operation{
    31  	State:       "FINISHED",
    32  	ProcessID:   "1000",
    33  	ProcessType: "DEPLOY",
    34  	Messages:    []*models.Message{&SimpleMessage},
    35  }
    36  
    37  var SimpleMtaLog = models.Log{
    38  	ID:          LogID,
    39  	DisplayName: "Test log",
    40  	Description: "Test log",
    41  }
    42  
    43  const ProcessID = "1000"
    44  const LogID = "OPERATION.log"
    45  const LogContent = "test-test-test"
    46  
    47  //
    48  type RuntimeResponse struct {
    49  	code    int
    50  	message string
    51  }
    52  
    53  func (r RuntimeResponse) Code() int {
    54  	return r.code
    55  }
    56  
    57  func (r RuntimeResponse) Message() string {
    58  	return r.message
    59  }
    60  
    61  func (r RuntimeResponse) GetHeader(header string) string {
    62  	return ""
    63  }
    64  
    65  func (r RuntimeResponse) Body() io.ReadCloser {
    66  	return nil
    67  }
    68  
    69  // generate a custom APIError for mocking test failures
    70  func NewCustomError(customCode int, opName, customMessage string) *runtime.APIError {
    71  	var customResponse = RuntimeResponse{
    72  		code:    customCode,
    73  		message: customMessage,
    74  	}
    75  
    76  	return runtime.NewAPIError(opName, customResponse, customCode)
    77  }
    78  
    79  //
    80  var notFoundResponse = RuntimeResponse{
    81  	code:    404,
    82  	message: "Process with id 404 not found",
    83  }
    84  
    85  //
    86  var ClientError = &runtime.APIError{
    87  	OperationName: "Getting process",
    88  	Response:      notFoundResponse,
    89  	Code:          404,
    90  }
    91  
    92  //
    93  //D41D8CD98F00B204E9800998ECF8427E -> MD5 hash for empty file
    94  var SimpleFile = models.FileMetadata{
    95  	ID:              "test.mtar",
    96  	Digest:          "D41D8CD98F00B204E9800998ECF8427E",
    97  	Name:            "test.mtar",
    98  	DigestAlgorithm: "MD5",
    99  	Space:           "test-space",
   100  	Namespace:       "namespace",
   101  }
   102  
   103  //
   104  func GetFile(file os.File, digest string, namespace string) *models.FileMetadata {
   105  	stat, _ := os.Stat(file.Name())
   106  	return &models.FileMetadata{
   107  		ID:              stat.Name(),
   108  		Space:           "test-space",
   109  		Name:            stat.Name(),
   110  		Namespace:       namespace,
   111  		Digest:          digest,
   112  		DigestAlgorithm: "MD5",
   113  	}
   114  }
   115  
   116  
   117  func GetOperation(processID, spaceID string, mtaID string, namespace string, processType string, state string, acquiredLock bool) *models.Operation {
   118  	return &models.Operation{
   119  		ProcessID:    processID,
   120  		ProcessType:  processType,
   121  		StartedAt:    "2016-03-04T14:23:24.521Z[Etc/UTC]",
   122  		SpaceID:      spaceID,
   123  		User:         "admin",
   124  		State:        models.State(state),
   125  		AcquiredLock: acquiredLock,
   126  		MtaID:        mtaID,
   127  		Namespace:    namespace,
   128  	}
   129  }
   130  
   131  //
   132  func GetMta(id, version string, namespace string, modules []*models.Module, services []string) *models.Mta {
   133  	return &models.Mta{
   134  		Metadata: &models.Metadata{
   135  			ID:        id,
   136  			Version:   version,
   137  			Namespace: namespace,
   138  		},
   139  		Modules:  modules,
   140  		Services: services,
   141  	}
   142  }
   143  
   144  //
   145  func GetMtaModule(name string, services []string, providedDependencies []string) *models.Module {
   146  	return &models.Module{
   147  		ModuleName:            name,
   148  		AppName:               name,
   149  		Services:              services,
   150  		ProvidedDendencyNames: providedDependencies,
   151  	}
   152  }
   153