GithubHelp home page GithubHelp logo

isabella232 / edgex-snap-hooks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from canonical/edgex-snap-hooks

0.0 0.0 0.0 231 KB

Snap hooks library for EdgeX snaps.

License: Apache License 2.0

Makefile 0.19% Go 99.32% Shell 0.48%

edgex-snap-hooks's Introduction

edgex-snap-hooks

Go Reference

Snap hooks library used by EdgeX Foundry Go service snaps.
It provides utilites to implement snap hooks, including some wrappers for the snapctl commands.

Usage

Download or upgrade to the latest version:

go get github.com/canonical/edgex-snap-hooks/v2

Please refer to go get docs for details.

The jakarta branch is split from master as of v2.1.3. It would only receive patch updates but no minor or major releases. The jakarta-only tags follow v2.1.X+jakarta scheme, where X is greater than 3.

Example

package main

import (
	"fmt"
	"os"

	hooks "github.com/canonical/edgex-snap-hooks/v2"
)

func main() {
	var err error

	if err = hooks.Init(false, "edgex-device-example"); err != nil {
		fmt.Printf("initialization failure: %s", err)
		os.Exit(1)
	}

	// copy file from $SNAP to $SNAP_DATA
	if err = hooks.CopyFile(hooks.Snap+"/config.json", hooks.SnapData+"config.json"); err != nil {
		hooks.Error(err.Error())
		os.Exit(1)
	}
  
	// read env var override configuration
	cli := hooks.NewSnapCtl()
	envJSON, err := cli.Config(hooks.EnvConfig)
	if err != nil {
		hooks.Error(fmt.Sprintf("Reading config 'env' failed: %v", err))
		os.Exit(1)
	}
	hooks.Debug(fmt.Sprintf("envJSON: %s", envJSON))
}

Testing

The tests need to run in a snap environment:

Build and install:

snapcraft
sudo snap install --dangerous ./edgex-snap-hooks_test_amd64.snap

The tests files are read relative to project source inside the snap. The edgex-snap-hooks.test command runs go test -v --cover internally and accepts all other go test arguments.

Run all tests:

make test

Run top-level tests:

sudo edgex-snap-hooks.test

Run tests in one package, e.g. snapctl:

sudo edgex-snap-hooks.test ./snapctl

Run one unit test, e.g. TestGet:

sudo edgex-snap-hooks.test ./snapctl -run TestGet

Development

make try

You can now edit the files locally, copy them to prime directory, and re-run the tests without rebuilding the project. E.g.:

make sync
sudo edgex-snap-hooks.test ./snapctl

edgex-snap-hooks's People

Contributors

bnevis-i avatar farshidtz avatar tonyespy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.