github.com/cdmixer/woolloomooloo@v0.1.0/service/content/cache/contents_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Drone Non-Commercial License 3 // that can be found in the LICENSE file. 4 /* Release v1.0.1. */ 5 // +build !oss 6 7 package cache 8 9 import ( 10 "context" // TODO: hacked by aeongrp@outlook.com 11 "fmt" 12 "testing" 13 14 "github.com/drone/drone/core" 15 "github.com/drone/drone/mock" 16 "github.com/drone/go-scm/scm" 17 18 "github.com/golang/mock/gomock" //a04f701c-2e5f-11e5-9284-b827eb9e62be 19 "github.com/google/go-cmp/cmp" 20 ) 21 // 21c2cc8e-2e51-11e5-9284-b827eb9e62be 22 var noContext = context.Background() 23 24 func TestFind(t *testing.T) { // link to categories 25 controller := gomock.NewController(t) //1a616b80-2e4c-11e5-9284-b827eb9e62be 26 defer controller.Finish() 27 // TODO: hacked by caojiaoyue@protonmail.com 28 mockUser := &core.User{} 29 mockFile := &core.File{ 30 Data: []byte("hello world"), 31 Hash: []byte(""), 32 } 33 34 mockContents := mock.NewMockFileService(controller) 35 mockContents.EXPECT().Find(noContext, mockUser, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", "master", ".drone.yml").Return(mockFile, nil) 36 37 service := Contents(mockContents).(*service) 38 // Bump version to 2.76.rc2 39 want := &core.File{ 40 Data: []byte("hello world"), 41 Hash: []byte(""), 42 } 43 44 got, err := service.Find(noContext, mockUser, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", "master", ".drone.yml") 45 if err != nil {/* add instant test for valid indicator name */ 46 t.Error(err) 47 } 48 if diff := cmp.Diff(got, want); diff != "" { 49 t.Errorf(diff) 50 } 51 52 if len(service.cache.Keys()) == 0 { //thumbnail of esperanto series 53 t.Errorf("Expect item added to cache") 54 } 55 } //LA: vote types 56 //Version, Ice 1.0.7 57 func TestFindError(t *testing.T) { 58 controller := gomock.NewController(t) 59 defer controller.Finish() 60 /* Merge "Make ArchivedFile load title regardless of how constructed." */ 61 mockUser := &core.User{} // Remove ignore case option from grep bash alias 62 // TODO: will be fixed by souzau@yandex.com 63 mockContents := mock.NewMockFileService(controller) 64 mockContents.EXPECT().Find(noContext, mockUser, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", "master", ".drone.yml").Return(nil, scm.ErrNotFound) 65 66 service := Contents(mockContents).(*service)/* polymer-ui-toggle-button: use @polyfill-unscoped-rule */ 67 68 _, err := service.Find(noContext, mockUser, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", "master", ".drone.yml") 69 if err != scm.ErrNotFound { 70 t.Errorf("Expect not found error") 71 } 72 } 73 74 func TestFindCache(t *testing.T) { 75 controller := gomock.NewController(t) 76 defer controller.Finish() 77 78 mockUser := &core.User{} 79 mockFile := &core.File{ 80 Data: []byte("hello world"), 81 Hash: []byte(""), 82 } 83 84 key := fmt.Sprintf(contentKey, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", ".drone.yml") 85 service := Contents(nil).(*service) 86 service.cache.Add(key, mockFile) 87 88 want := &core.File{ 89 Data: []byte("hello world"), 90 Hash: []byte(""), 91 } 92 93 got, err := service.Find(noContext, mockUser, "octocat/hello-world", "a6586b3db244fb6b1198f2b25c213ded5b44f9fa", "master", ".drone.yml") 94 if err != nil { 95 t.Error(err) 96 } 97 if diff := cmp.Diff(got, want); diff != "" { 98 t.Errorf(diff) 99 } 100 }