1// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved. 2// 3// Use of this source code is governed by a BSD-style 4// license that can be found in the LICENSE file. 5 6package travis 7 8import ( 9 "context" 10 "fmt" 11 "net/http" 12 "reflect" 13 "testing" 14) 15 16func TestCachesService_ListByRepoId(t *testing.T) { 17 client, mux, _, teardown := setup() 18 defer teardown() 19 20 mux.HandleFunc(fmt.Sprintf("/repo/%d/caches", testRepoId), func(w http.ResponseWriter, r *http.Request) { 21 testMethod(t, r, http.MethodGet) 22 fmt.Fprint(w, `{"caches": [{"branch":"master","match":"test"}]}`) 23 }) 24 25 caches, _, err := client.Caches.ListByRepoId(context.Background(), testRepoId) 26 27 if err != nil { 28 t.Errorf("Caches.FindByRepoId returned error: %v", err) 29 } 30 31 want := []*Cache{{Branch: "master", Match: "test"}} 32 if !reflect.DeepEqual(caches, want) { 33 t.Errorf("Caches.FindByRepoId returned %+v, want %+v", caches, want) 34 } 35} 36 37func TestCachesService_ListByRepoSlug(t *testing.T) { 38 client, mux, _, teardown := setup() 39 defer teardown() 40 41 mux.HandleFunc(fmt.Sprintf("/repo/%s/caches", testRepoSlug), func(w http.ResponseWriter, r *http.Request) { 42 testMethod(t, r, http.MethodGet) 43 fmt.Fprint(w, `{"caches": [{"branch":"master","match":"test"}]}`) 44 }) 45 46 caches, _, err := client.Caches.ListByRepoSlug(context.Background(), testRepoSlug) 47 48 if err != nil { 49 t.Errorf("Caches.FindByRepoSlug returned error: %v", err) 50 } 51 52 want := []*Cache{{Branch: "master", Match: "test"}} 53 if !reflect.DeepEqual(caches, want) { 54 t.Errorf("Caches.FindByRepoSlug returned %+v, want %+v", caches, want) 55 } 56} 57 58func TestCachesService_DeleteByRepoId(t *testing.T) { 59 client, mux, _, teardown := setup() 60 defer teardown() 61 62 mux.HandleFunc(fmt.Sprintf("/repo/%d/caches", testRepoId), func(w http.ResponseWriter, r *http.Request) { 63 testMethod(t, r, http.MethodDelete) 64 fmt.Fprint(w, `{"caches": [{"branch":"master","match":"test"}]}`) 65 }) 66 67 caches, _, err := client.Caches.DeleteByRepoId(context.Background(), testRepoId) 68 69 if err != nil { 70 t.Errorf("Caches.DeleteByRepoId returned error: %v", err) 71 } 72 73 want := []*Cache{{Branch: "master", Match: "test"}} 74 if !reflect.DeepEqual(caches, want) { 75 t.Errorf("Caches.DeleteByRepoId returned %+v, want %+v", caches, want) 76 } 77} 78 79func TestCachesService_DeleteByRepoSlug(t *testing.T) { 80 client, mux, _, teardown := setup() 81 defer teardown() 82 83 mux.HandleFunc(fmt.Sprintf("/repo/%s/caches", testRepoSlug), func(w http.ResponseWriter, r *http.Request) { 84 testMethod(t, r, http.MethodDelete) 85 fmt.Fprint(w, `{"caches": [{"branch":"master","match":"test"}]}`) 86 }) 87 88 caches, _, err := client.Caches.DeleteByRepoSlug(context.Background(), testRepoSlug) 89 90 if err != nil { 91 t.Errorf("Caches.DeleteByRepoSlug returned error: %v", err) 92 } 93 94 want := []*Cache{{Branch: "master", Match: "test"}} 95 if !reflect.DeepEqual(caches, want) { 96 t.Errorf("Caches.DeleteByRepoSlug returned %+v, want %+v", caches, want) 97 } 98} 99