keon94 commented on code in PR #5085:
URL: 
https://github.com/apache/incubator-devlake/pull/5085#discussion_r1226931415


##########
backend/test/e2e/manual/pagerduty/pagerduty_test.go:
##########
@@ -0,0 +1,164 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package pagerduty
+
+import (
+       "fmt"
+       "github.com/apache/incubator-devlake/core/config"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       "github.com/apache/incubator-devlake/plugins/pagerduty/impl"
+       pluginmodels 
"github.com/apache/incubator-devlake/plugins/pagerduty/models"
+       "github.com/apache/incubator-devlake/test/helper"
+       "github.com/stretchr/testify/require"
+       "testing"
+       "time"
+)
+
+const pluginName = "pagerduty"
+
+func TestPagerDutyPlugin(t *testing.T) {
+       cfg := helper.GetTestConfig[TestConfig]()
+       client := helper.ConnectLocalServer(t, &helper.LocalClientConfig{
+               ServerPort:   8089,
+               DbURL:        config.GetConfig().GetString("E2E_DB_URL"),
+               CreateServer: true,
+               DropDb:       false,
+               TruncateDb:   true,
+               Plugins: map[string]plugin.PluginMeta{
+                       pluginName: &impl.PagerDuty{},
+               },
+       })
+       client.SetTimeout(0)
+       client.SetPipelineTimeout(0)
+       connection := createConnection(cfg, client)
+       t.Run("blueprint v200", func(t *testing.T) {
+               serviceScopes := helper.RemoteScopesOutput{}
+               var scopeData []any
+               for {
+                       serviceScopes = 
client.RemoteScopes(helper.RemoteScopesQuery{
+                               PluginName:   pluginName,
+                               ConnectionId: connection.ID,
+                               PageToken:    serviceScopes.NextPageToken,
+                               Params:       nil,
+                       })
+                       for _, remoteScope := range serviceScopes.Children {
+                               if remoteScope.Type == "scope" {
+                                       data := 
helper.Cast[pluginmodels.Service](remoteScope.Data)
+                                       for _, serviceName := range 
cfg.Services {
+                                               if serviceName == data.Name {
+                                                       scopeData = 
append(scopeData, &data)
+                                               }
+                                       }
+                               }
+                       }
+                       if serviceScopes.NextPageToken == "" {
+                               break
+                       }
+               }
+               createdScopes := 
helper.Cast[[]*pluginmodels.Service](client.CreateScope(pluginName, 
connection.ID, scopeData...))
+               require.True(t, len(createdScopes) > 0)
+               uniqueString := time.Now().Format(time.RFC3339)
+               outputProject := createProject(client, 
fmt.Sprintf("pagerduty-project-%s-%s", pluginName, uniqueString))
+               var bpScopes []*plugin.BlueprintScopeV200
+               for _, scope := range createdScopes {
+                       bpScopes = append(bpScopes, &plugin.BlueprintScopeV200{
+                               Id:   scope.Id,
+                               Name: 
fmt.Sprintf("pagerduty-blueprint-v200-%s", uniqueString),
+                       })
+               }
+               bp := client.CreateBasicBlueprintV2(connection.Name, 
&helper.BlueprintV2Config{
+                       Connection: &plugin.BlueprintConnectionV200{
+                               Plugin:       pluginName,
+                               ConnectionId: connection.ID,
+                               Scopes:       bpScopes,
+                       },
+                       TimeAfter:   cfg.TimeSince,
+                       SkipOnFail:  false,
+                       ProjectName: outputProject.Name,
+               })
+               // get the project ... should have a reference to the blueprint 
now
+               outputProject = client.GetProject(outputProject.Name)
+               require.Equal(t, bp.Name, outputProject.Blueprint.Name)
+               fmt.Printf("=========================Triggering blueprint for 
project %s =========================\n", outputProject.Name)
+               client.TriggerBlueprint(bp.ID)
+               createdScopesList := client.ListScopes(pluginName, 
connection.ID, true)
+               require.True(t, len(createdScopesList) > 0)
+               for _, scope := range createdScopesList {
+                       scopeCast := 
helper.Cast[pluginmodels.Service](scope.Scope)
+                       fmt.Printf("Deleting scope %s\n", scopeCast.Id)
+                       client.DeleteScope(pluginName, connection.ID, 
scopeCast.Id, false)
+                       fmt.Printf("Deleted scope %s\n", scopeCast.Id)
+               }
+       })
+       fmt.Println("======DONE======")
+       time.Sleep(120 * time.Minute)

Review Comment:
   Yeah this was intentional so I could have time to check the DB tables and 
validate their data. There's technically no need to poll here because the 
Trigger function already does this. We can just remove these Sleeps and do this 
instead:
   ```go
                pipeline := client.TriggerBlueprint(bp.ID)
                require.Equal(t, models.TASK_COMPLETED, pipeline.Status)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to